package com.shenhaofeng.demo.activity;

import android.graphics.Color;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.view.PagerAdapter;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.shenhaofeng.app.component.BaseActivity;
import com.shenhaofeng.app.widget.banner.Banner;
import com.shenhaofeng.demo.R;

import java.util.concurrent.TimeUnit;


/**
 * Created by Administrator on 2016/9/29.
 */
public class BannerActivity extends BaseActivity {
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Banner banner=new Banner(this);
        setContentView(banner);
        banner.setAutoScroll(3, TimeUnit.SECONDS);
        banner.setBannerPagerAdapter(new BannerAdapter());
    }


    class BannerAdapter extends PagerAdapter {

        @Override
        public int getCount() {
            return 5;
        }


        @Override
        public boolean isViewFromObject(View view, Object object) {
            return view == object;
        }


        @Override
        public Object instantiateItem(ViewGroup container, int position) {
            ImageView imageView=new ImageView(container.getContext());
            imageView.setImageResource(R.mipmap.ic_launcher);
            imageView.setScaleType(ImageView.ScaleType.CENTER);
            imageView.setBackgroundColor(Color.GRAY);
            container.addView(imageView);
            return imageView;
        }


        @Override
        public void destroyItem(ViewGroup container, int position, Object object) {
            container.removeView((View) object);
        }
    }
}
